package com.lt.basic.project.pojo.entity.mino.user;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lt.basic.project.common.uid.Id;
import com.lt.basic.project.common.util.StringUtils;
import com.lt.basic.project.pojo.validate.mino.user.UserCreateValidate;
import com.lt.basic.project.pojo.validate.mino.user.UserUpdateValidate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 用户信息表(basic_user)数据实体
 * @author ：LT
 * @Created in : 2023-11-27
 */

@Data
@ApiModel(value = "User对象", description = "用户信息表(basic_user)表")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    private Long id;

    /**
     * 编号
     */
    private Integer sn;

    /**
     * 头像
     */
    private String avatar;

    /**
     * 真实姓名
     */
    private String realName;

    /**
     * 用户昵称
     */
    private String nickname;

    /**
     * 用户账号
     */
    private String username;

    /**
     * 用户密码
     */
    private String password;

    /**
     * 用户电话
     */
    private String mobile;

    /**
     * 用户钱包
     */
    private BigDecimal money;

    /**
     * 加密盐巴
     */
    private String salt;

    /**
     * 用户性别: [1=男, 2=女]
     */
    private Integer sex;

    /**
     * 注册渠道: [1=微信小程序, 2=微信公众号, 3=手机H5, 4=电脑PC, 5=苹果APP, 6=安卓APP]
     */
    private Integer channel;

    /**
     * 是否禁用: [0=否, 1=是]
     */
    private Integer isDisable;

    /**
     * 是否删除: [0=否, 1=是]
     */
    private Integer isDelete;

    /**
     * 是否是新注册用户: [1-是, 0-否]
     */
    private Integer isNew;

    /**
     * 最后登录IP
     */
    private String lastLoginIp;

    /**
     * 最后登录时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastLoginTime;

    /**
     * 创建时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    /**
     * 更新时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    /**
     * 删除时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date deleteTime;


    /**
    * 添加数据
    */
    public void create(UserCreateValidate createValidate) {
        setId(Id.getId());
        setSn(createValidate.getSn());
        setAvatar(createValidate.getAvatar());
        setRealName(createValidate.getRealName());
        setNickname(createValidate.getNickname());
        setUsername(createValidate.getUsername());
        setPassword(createValidate.getPassword());
        setMobile(createValidate.getMobile());
        setMoney(createValidate.getMoney());
        setSalt(createValidate.getSalt());
        setSex(createValidate.getSex());
        setChannel(createValidate.getChannel());
        setIsDisable(createValidate.getIsDisable());
        setIsDelete(createValidate.getIsDelete());
        setIsNew(createValidate.getIsNew());
        setLastLoginIp(createValidate.getLastLoginIp());
        setLastLoginTime(createValidate.getLastLoginTime());
        setCreateTime(new Date());
        setDeleteTime(createValidate.getDeleteTime());
    }

    /**
    * 编辑数据
    */
    public void modify(UserUpdateValidate updateValidate) {
        if (StringUtils.isNotObj(updateValidate.getSn())) {
            setSn(updateValidate.getSn());
        }
        if (StringUtils.isNotObj(updateValidate.getAvatar())) {
            setAvatar(updateValidate.getAvatar());
        }
        if (StringUtils.isNotObj(updateValidate.getRealName())) {
            setRealName(updateValidate.getRealName());
        }
        if (StringUtils.isNotObj(updateValidate.getNickname())) {
            setNickname(updateValidate.getNickname());
        }
        if (StringUtils.isNotObj(updateValidate.getUsername())) {
            setUsername(updateValidate.getUsername());
        }
        if (StringUtils.isNotObj(updateValidate.getPassword())) {
            setPassword(updateValidate.getPassword());
        }
        if (StringUtils.isNotObj(updateValidate.getMobile())) {
            setMobile(updateValidate.getMobile());
        }
        if (StringUtils.isNotObj(updateValidate.getMoney())) {
            setMoney(updateValidate.getMoney());
        }
        if (StringUtils.isNotObj(updateValidate.getSalt())) {
            setSalt(updateValidate.getSalt());
        }
        if (StringUtils.isNotObj(updateValidate.getSex())) {
            setSex(updateValidate.getSex());
        }
        if (StringUtils.isNotObj(updateValidate.getChannel())) {
            setChannel(updateValidate.getChannel());
        }
        if (StringUtils.isNotObj(updateValidate.getIsDisable())) {
            setIsDisable(updateValidate.getIsDisable());
        }
        if (StringUtils.isNotObj(updateValidate.getIsDelete())) {
            setIsDelete(updateValidate.getIsDelete());
        }
        if (StringUtils.isNotObj(updateValidate.getIsNew())) {
            setIsNew(updateValidate.getIsNew());
        }
        if (StringUtils.isNotObj(updateValidate.getLastLoginIp())) {
            setLastLoginIp(updateValidate.getLastLoginIp());
        }
        if (StringUtils.isNotObj(updateValidate.getLastLoginTime())) {
            setLastLoginTime(updateValidate.getLastLoginTime());
        }
        setUpdateTime(new Date());
        if (StringUtils.isNotObj(updateValidate.getDeleteTime())) {
            setDeleteTime(updateValidate.getDeleteTime());
        }
    }

}